package net.wanho.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class R {

    private Integer code;

    private boolean success;

    private String message;

    private Object data;

    public static R success() {
        return new R(HttpStatus.OK.value(),true, "success", null);
    }

    public static R success(String message) {
        return new R(HttpStatus.OK.value(),true, message, null);
    }

    public static R success(Object data) {
        return new R(HttpStatus.OK.value(),true, "success", data);
    }

    public static R success(String message, Object data) {
        return new R(HttpStatus.OK.value(),true, message, data);
    }

    public static R success(int code, Object data) {
        return new R(code,true, "success", data);
    }

    public static R success(int code, String message) {
        return new R(code, true,message, null);
    }

    public static R success(int code, String message, Object data) {
        return new R(code, true,message, data);
    }

    public static R error(String message) {
        return new R(HttpStatus.INTERNAL_SERVER_ERROR.value(),false, message, null);
    }

    public static R error(int code, String message) {
        return new R(code,false, message, null);
    }
    public static R error(Object data){
        return new R(HttpStatus.INTERNAL_SERVER_ERROR.value(),false,null, data);
    }
}
